package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.archive.letax.LetaxAccount;
import com.tengju.user.domain.model.archive.letax.LetaxAccountId;
import com.tengju.user.domain.model.archive.letax.LetaxStatus;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.AccountId;
import com.tengju.user.domain.shared.DateUtil;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.LetaxAccountDO;

public class LetaxAccountConvert {

    public static LetaxAccount convert(LetaxAccountDO letaxAccountDO) {
        if (letaxAccountDO == null) {
            return null;
        }
        return new LetaxAccount(
                new LetaxAccountId(letaxAccountDO.getId()),
                new UserIdCode(letaxAccountDO.getIdCode()),
                new AccountId(letaxAccountDO.getAccountId()),
                letaxAccountDO.getBankNo(),
                letaxAccountDO.getBankName(),
                letaxAccountDO.getIdcardNo(),
                letaxAccountDO.getIdcardName(),
                letaxAccountDO.getRemark(),
                LetaxStatus.form(letaxAccountDO.getStatus()),
                DateUtil.dateToLocalDateTime(letaxAccountDO.getCheckAt()),
                DateUtil.dateToLocalDateTime(letaxAccountDO.getCreatedAt()));
    }

    public static LetaxAccountDO convert(LetaxAccount letaxAccount) {
        if (letaxAccount == null) {
            return null;
        }
        LetaxAccountDO letaxAccountDO = new LetaxAccountDO();
        letaxAccountDO.setIdCode(letaxAccount.getUserIdCode().getValue());
        letaxAccountDO.setAccountId(letaxAccount.getAccountId().getValue());
        letaxAccountDO.setBankNo(letaxAccount.getBankNo());
        letaxAccountDO.setBankName(letaxAccount.getBankName());
        letaxAccountDO.setIdcardNo(letaxAccount.getIdCardNo());
        letaxAccountDO.setIdcardName(letaxAccount.getIdCardName());
        letaxAccountDO.setRemark(letaxAccount.getRemark());
        letaxAccountDO.setStatus(letaxAccount.getStatus().getVal());
        letaxAccountDO.setCheckAt(DateUtil.localDateTimeToDate(letaxAccount.getCheckTime()));
        letaxAccountDO.setPlatformCode(letaxAccount.getPlatformCode());
        return letaxAccountDO;
    }

    public static LetaxAccountDO convert(LetaxAccountId letaxAccountId, LetaxAccount letaxAccount) {
        if (letaxAccountId == null || letaxAccount == null) {
            return null;
        }
        LetaxAccountDO letaxAccountDO = convert(letaxAccount);
        letaxAccountDO.setId(letaxAccountId.getValue());
        return letaxAccountDO;
    }
}
